package com.ytzl.itrip.service.impl;

import com.ytzl.itrip.dao.ItripHotelOrderMapper;
import com.ytzl.itrip.service.ItripHotelOrderService;
import com.ytzl.itrip.pojo.ItripHotelOrder;
import com.ytzl.itrip.common.EmptyUtils;
import com.ytzl.itrip.common.Constants;
import com.ytzl.itrip.common.Page;
import com.ytzl.itrip.vo.order.ItripPersonalOrderRoomInfoVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class ItripHotelOrderServiceImpl implements ItripHotelOrderService {

    @Resource
    private ItripHotelOrderMapper itripHotelOrderMapper;

    public ItripHotelOrder getItripHotelOrderById(Long id) throws Exception {
        return itripHotelOrderMapper.getItripHotelOrderById(id);
    }

    public Integer removeItripHotelOrderById(Long id) throws Exception {
        return itripHotelOrderMapper.removeItripHotelOrderById(id);
    }

    public List<ItripHotelOrder> getItripHotelOrderListByMap(Map
                                                                     <String, Object> param) throws Exception {
        List<ItripHotelOrder> list = itripHotelOrderMapper.getItripHotelOrderListByMap(param);
        return list;
    }

    public Integer getItripHotelOrderCountByMap(Map
                                                        <String, Object> param) throws Exception {
        return itripHotelOrderMapper.getItripHotelOrderCountByMap(param);
    }

    public Integer saveItripHotelOrder(ItripHotelOrder itripHotelOrder) throws Exception {
        itripHotelOrder.setCreationDate(new Date());
        return itripHotelOrderMapper.saveItripHotelOrder(itripHotelOrder);
    }

    public Integer modifyItripHotelOrder(ItripHotelOrder itripHotelOrder) throws Exception {
        itripHotelOrder.setModifyDate(new Date());
        return itripHotelOrderMapper.modifyItripHotelOrder(itripHotelOrder);
    }

    public Integer removeItripHotelOrderByIds(Long[] ids) throws Exception {
        return itripHotelOrderMapper.removeItripHotelOrderByIds(ids);
    }
    @Override
    public ItripPersonalOrderRoomInfoVO getHotelOrderRoomInfoByOrderId(Long orderId) {
        return itripHotelOrderMapper.getHotelOrderRoomInfoByOrderId(orderId);
    }

    public Page<ItripHotelOrder> queryItripHotelOrderPageByMap(Map<String, Object> param, Integer pageNo, Integer pageSize) throws Exception {
        Integer total = itripHotelOrderMapper.getItripHotelOrderCountByMap(param);
        pageNo = EmptyUtils.isEmpty(pageNo) ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = EmptyUtils.isEmpty(pageSize) ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<ItripHotelOrder> itripHotelOrderList = itripHotelOrderMapper.getItripHotelOrderListByMap(param);
        page.setRows(itripHotelOrderList);
        return page;
    }

}
